/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UserDashboard.java
 *
 * Created on Jul 1, 2011, 3:42:49 AM
 */

package javadatabasegui;

import java.awt.Component;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.GroupLayout;
import javax.swing.JOptionPane;

/**
 *
 * @author PM
 */
public class UserDashboard extends javax.swing.JFrame {
    Connection con;
    String userEmail;
    /** Creates new form UserDashboard */
    public UserDashboard(String email, Connection conn){
        userEmail = email;
        con = conn;
        initComponents();
        displayProjectTable();
        displayTaskTable();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dashboardName = new javax.swing.JLabel();
        clkLogout = new javax.swing.JLabel();
        clkPrTskReport = new javax.swing.JLabel();
        clkEmTskReport = new javax.swing.JLabel();
        myprojectsPanel = new javax.swing.JPanel();
        newProjectButton = new javax.swing.JButton();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        jSeparator1 = new javax.swing.JSeparator();
        label4 = new java.awt.Label();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel3 = new javax.swing.JPanel();
        mytasksPanel = new javax.swing.JPanel();
        jSeparator2 = new javax.swing.JSeparator();
        label5 = new java.awt.Label();
        label6 = new java.awt.Label();
        label7 = new java.awt.Label();
        label8 = new java.awt.Label();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel2 = new javax.swing.JPanel();

        jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel4.setBackground(new java.awt.Color(230, 174, 39));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel2.setText("Select A Project");

        jScrollPane3.setBorder(null);

        jPanel5.setBackground(new java.awt.Color(230, 174, 39));
        jPanel5.setPreferredSize(new java.awt.Dimension(280, 170));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 281, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 171, Short.MAX_VALUE)
        );

        jScrollPane3.setViewportView(jPanel5);

        jLabel3.setText("Project ID");

        jLabel4.setText("Project Name");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38)
                                .addComponent(jLabel4)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GT Project Manager - User Dashboard");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(230, 174, 39));
        jPanel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel1.setPreferredSize(new java.awt.Dimension(1000, 724));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText("Dashboard For");

        dashboardName.setFont(new java.awt.Font("Tahoma", 1, 18));
        dashboardName.setText(getDashName());

        clkLogout.setFont(new java.awt.Font("Tahoma", 0, 12));
        clkLogout.setForeground(new java.awt.Color(0, 0, 255));
        clkLogout.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        clkLogout.setText("<html><U>Log Out</U></html>");
        clkLogout.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        clkLogout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                goLogout(evt);
            }
        });

        clkPrTskReport.setFont(new java.awt.Font("Tahoma", 0, 12));
        clkPrTskReport.setForeground(new java.awt.Color(0, 0, 255));
        clkPrTskReport.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        clkPrTskReport.setText("<html><U>Project Tasks Report</U><html>");
        clkPrTskReport.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        clkPrTskReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clickProjectTaskReport(evt);
            }
        });

        clkEmTskReport.setFont(new java.awt.Font("Tahoma", 0, 12));
        clkEmTskReport.setForeground(new java.awt.Color(0, 0, 255));
        clkEmTskReport.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        clkEmTskReport.setText("<html><U>Employee Tasks Report</U></html>");
        clkEmTskReport.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        clkEmTskReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                goEmployeeTaskReport(evt);
            }
        });

        myprojectsPanel.setBackground(new java.awt.Color(255, 255, 255));

        newProjectButton.setFont(new java.awt.Font("Tahoma", 1, 11));
        newProjectButton.setText("New Project");
        newProjectButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                newProjectButtonMouseClicked(evt);
            }
        });

        label1.setFont(new java.awt.Font("Tahoma", 1, 20));
        label1.setText("My Projects");

        label2.setFont(new java.awt.Font("Tahoma", 1, 18));
        label2.setText("ID");

        label3.setFont(new java.awt.Font("Tahoma", 1, 18));
        label3.setText("Project Title");

        label4.setFont(new java.awt.Font("Tahoma", 1, 18));
        label4.setText("My Role");

        jScrollPane1.setBorder(null);
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setPreferredSize(new java.awt.Dimension(869, 175));
        jPanel3.setRequestFocusEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 869, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 175, Short.MAX_VALUE)
        );

        jScrollPane1.setViewportView(jPanel3);

        javax.swing.GroupLayout myprojectsPanelLayout = new javax.swing.GroupLayout(myprojectsPanel);
        myprojectsPanel.setLayout(myprojectsPanelLayout);
        myprojectsPanelLayout.setHorizontalGroup(
            myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(myprojectsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 874, Short.MAX_VALUE)
                    .addGroup(myprojectsPanelLayout.createSequentialGroup()
                        .addGroup(myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(myprojectsPanelLayout.createSequentialGroup()
                                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 623, Short.MAX_VALUE)
                                .addComponent(newProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(myprojectsPanelLayout.createSequentialGroup()
                        .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(89, 89, 89)
                        .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 330, Short.MAX_VALUE)
                        .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(94, 94, 94))))
        );
        myprojectsPanelLayout.setVerticalGroup(
            myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(myprojectsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(newProjectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(myprojectsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36))
        );

        mytasksPanel.setBackground(new java.awt.Color(255, 255, 255));
        mytasksPanel.setPreferredSize(new java.awt.Dimension(901, 238));

        label5.setFont(new java.awt.Font("Tahoma", 1, 18));
        label5.setText("Due Date");

        label6.setFont(new java.awt.Font("Tahoma", 1, 18));
        label6.setText("Project Title");

        label7.setFont(new java.awt.Font("Tahoma", 1, 18));
        label7.setText("Task Name");

        label8.setFont(new java.awt.Font("Tahoma", 1, 20));
        label8.setText("My Tasks");

        jScrollPane2.setBorder(null);
        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setPreferredSize(new java.awt.Dimension(880, 194));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 880, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 194, Short.MAX_VALUE)
        );

        jScrollPane2.setViewportView(jPanel2);

        javax.swing.GroupLayout mytasksPanelLayout = new javax.swing.GroupLayout(mytasksPanel);
        mytasksPanel.setLayout(mytasksPanelLayout);
        mytasksPanelLayout.setHorizontalGroup(
            mytasksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mytasksPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mytasksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 874, Short.MAX_VALUE)
                    .addGroup(mytasksPanelLayout.createSequentialGroup()
                        .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(239, 239, 239))
                    .addGroup(mytasksPanelLayout.createSequentialGroup()
                        .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(100, 100, 100)
                        .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 281, Short.MAX_VALUE)
                        .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(41, 41, 41))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mytasksPanelLayout.createSequentialGroup()
                        .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 864, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        mytasksPanelLayout.setVerticalGroup(
            mytasksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mytasksPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mytasksPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(label7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(6, 6, 6)
                                .addComponent(dashboardName, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(348, 348, 348)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(clkLogout, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(clkPrTskReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(clkEmTskReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(mytasksPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 884, Short.MAX_VALUE)
                            .addComponent(myprojectsPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(dashboardName, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(clkLogout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(clkPrTskReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(clkEmTskReport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(16, 16, 16)
                .addComponent(myprojectsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(mytasksPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 920, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 656, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void goLogout(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goLogout
        // TODO add your handling code here:
        new LoginScreen(con).setVisible(true);
        this.dispose();
    }//GEN-LAST:event_goLogout

    private void clickProjectTaskReport(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clickProjectTaskReport
        
        int numEntries = 0;
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT COUNT(PID) from `cs4400_Group_14`.`Project` WHERE Mgr_Email = \""+userEmail+"\"")){
                rs = stmt.getResultSet();
            }
            rs.next();
            numEntries = rs.getInt("COUNT(PID)");
        }catch(SQLException e){
            System.err.println("Error in Project Count");
            System.err.println(e.getMessage());
        }
        if(numEntries!=0){
        jPanel5.setPreferredSize(new java.awt.Dimension(322, numEntries*30));
        javax.swing.JLabel[] tstLabel = new javax.swing.JLabel[numEntries];
        
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i] = new javax.swing.JLabel();
        }
        String[] prj = new String[numEntries];
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT PID, P_Name from `cs4400_Group_14`.`Project` WHERE Mgr_Email = \""+userEmail+"\"")){
                rs = stmt.getResultSet();
            }
            for(int i=0; rs.next(); i++){
                prj[i] = rs.getInt("PID") + " - " + rs.getString("P_Name");
            }
        }catch(SQLException e){
            System.err.println("Error in Project Count");
            System.err.println(e.getMessage());
        }

        String s = (String)JOptionPane.showInputDialog(null,"Select Project", "Project Task Report", JOptionPane.PLAIN_MESSAGE,null, prj, prj[0]);
        if(s != null){
            int i = s.indexOf(" - ");
            int selectedPRJ = Integer.parseInt(s.substring(0,i));
            String prjNme = s.substring(i+3, s.length());
            new ProjectTaskReport(selectedPRJ, userEmail, prjNme, con).setVisible(true);
            this.dispose();
        }
        }
    }//GEN-LAST:event_clickProjectTaskReport


    private void goEmployeeTaskReport(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_goEmployeeTaskReport
       new EmpTaskReport(con, userEmail).setVisible(true);
                this.dispose();
    }//GEN-LAST:event_goEmployeeTaskReport

    private void newProjectButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_newProjectButtonMouseClicked
         new ProjectInfo(userEmail, con).setVisible(true);
         this.dispose();
    }//GEN-LAST:event_newProjectButtonMouseClicked

    
    private void projectMouseClicked(java.awt.event.MouseEvent evt) {
        Component cmp = evt.getComponent();         //this along with next line returns the name of component clicked
        new ProjectInfo(Integer.parseInt(cmp.getName()), userEmail, con).setVisible(true);
           this.dispose();
    }

    private void taskMouseClicked(java.awt.event.MouseEvent evt) {
        Component cmp = evt.getComponent();         //gets the component that was clicked
        String str = cmp.getName();                  //puts the component name into a string
        String separator = ":::";                   //what was used to separate the information

        int pID;
        String mName;
        String tName;
        Date dt = null;
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

        int i = str.indexOf(separator);
        pID = Integer.parseInt(str.substring(0,i));
        int j = str.indexOf(separator, i+1);
        mName = str.substring(i+3,j);
        i = str.indexOf(separator,j+1);
        tName = str.substring(j+3,i);
        j = str.indexOf(separator,i+1);
        try{
        dt = (Date)formatter.parse(str.substring(i+3,j));
        }catch(ParseException e){}
        new TimeTracking(con, userEmail, pID, mName, tName, dt).setVisible(true);
        this.dispose();
    }

    private String getDashName(){
        String dashName = "Name";
        //use userEmail to get the F_Name and L_Name
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT F_Name,L_Name FROM Users WHERE Email=\""
                    + userEmail +"\"")){
                rs = stmt.getResultSet();
            }
            rs.next();
            dashName = rs.getString("F_Name") + " " + rs.getString("L_Name");
        }catch(SQLException e){
            System.err.println(e.getMessage());
            System.err.println(e.getSQLState());
        }        
        return dashName;
    }

    private void displayProjectTable(){

        int numEntries = 0;
        
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT COUNT(PID) from `cs4400_Group_14`.`Project`")){
                rs = stmt.getResultSet();
            }
            rs.next();
            numEntries = rs.getInt("COUNT(PID)");
        }catch(SQLException e){
            System.err.println("Error in Project Count");
            System.err.println(e.getMessage());
        }
        
        jPanel3.setPreferredSize(new java.awt.Dimension(869, numEntries*25));
        javax.swing.JLabel[] tstLabel = new javax.swing.JLabel[numEntries];
        
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i] = new javax.swing.JLabel();
        }

        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT Project.PID,P_Name,Mgr_Email from `cs4400_Group_14`.`Project`, `cs4400_Group_14`.`User_WP` WHERE User_WP.Email = \""+userEmail+"\" AND Project.PID = User_WP.PID")){
                rs = stmt.getResultSet();
            }
         for(int i=0; rs.next();i++){
             String job;
             if (rs.getString("Mgr_Email").matches(userEmail))
             {
                 job = "Project Lead";
                 tstLabel[i].setText("<html> <body> <table width=\"860\"> <tr> <td width=\"15%\">" + rs.getInt("PID")
                    + "</td> <td width=\"60%\"> <span style=\"color:blue\">" + rs.getString("P_Name") + "</td>"
                    + "<td width=\"25%\">" + job + "</td> </tr> </table> </body> </html>");
                 tstLabel[i].setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
                 tstLabel[i].addMouseListener(new java.awt.event.MouseAdapter() {
                        @Override
                        public void mouseClicked(java.awt.event.MouseEvent evt) {
                            projectMouseClicked(evt);
                 }});
             }
             else
             {
                 job = "Project Member";
                 tstLabel[i].setText("<html> <body> <table width=\"860\"> <tr> <td width=\"15%\">" + rs.getInt("PID")
                    + "</td> <td width=\"60%\">" + rs.getString("P_Name") + "</td>"
                    + "<td width=\"25%\">" + job + "</td> </tr> </table> </body> </html>");
             }

            tstLabel[i].setName(Integer.toString(rs.getInt("PID")));           //THIS i WILL CHANGE TO THE ID OF THE PROJECT
        }           
        }catch(SQLException e){
            System.err.println("Error in Projects Display");
            System.err.println(e.getMessage());
            }


        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel2Layout);
        GroupLayout.SequentialGroup leftToRight = jPanel2Layout.createSequentialGroup();
        GroupLayout.ParallelGroup singleColumn = jPanel2Layout.createParallelGroup();
        for(int i=0; i<tstLabel.length; i++){
            singleColumn.addComponent(tstLabel[i], javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 860, Short.MAX_VALUE);
        }
        leftToRight.addGroup(singleColumn);

        GroupLayout.SequentialGroup topToBottom = jPanel2Layout.createSequentialGroup();
        GroupLayout.ParallelGroup rowTop = jPanel2Layout.createParallelGroup();
        topToBottom.addGroup(rowTop);
        for(int i=0; i<tstLabel.length; i++){
            topToBottom.addComponent(tstLabel[i], javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE);
        }
        jPanel2Layout.setHorizontalGroup(leftToRight);
        jPanel2Layout.setVerticalGroup(topToBottom);

    }

    private void displayTaskTable(){

        int numEntries = 15;
        
        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT COUNT(T_Name) from cs4400_Group_14.Tasks WHERE Tasks.U_Email =\"" + userEmail + "\" AND Status = 1")){
                rs = stmt.getResultSet();
            }
            rs.next();
            numEntries = rs.getInt("COUNT(T_Name)");
        }catch(SQLException e){
            System.err.println("Error in Task Count");
            System.err.println(e.getMessage());
            }
        
        javax.swing.JLabel[] tstLabel = new javax.swing.JLabel[numEntries];
        jPanel2.setPreferredSize(new java.awt.Dimension(869, numEntries*25));
        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i] = new javax.swing.JLabel();
        }

        try{
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            if (stmt.execute("SELECT T_Name, Tasks.PID, P_Name, Due_Date, M_Name FROM cs4400_Group_14.Tasks, cs4400_Group_14.Project WHERE Tasks.U_Email = \""
                    +userEmail+"\"AND Tasks.PID = Project.PID AND Status = 1 ORDER BY Due_Date")){
                rs = stmt.getResultSet();
            }
            Date currentDate = getDate();
            for(int i=0; rs.next();i++){
            //add if statement to change next part to red color if due date is passed. 799
                if( currentDate.before(rs.getDate("Due_Date")) )
                {
                    tstLabel[i].setText("<html> <body> <table width=\"860\"> <tr> <td width=\"30%\"> <u> <span style=\"color:blue\">" + rs.getString("T_Name") + "</u> </td>"
                            + "<td width=\"55%\">" + rs.getString("P_Name") +"</td>"
                            + "<td width=\"15%\">" + rs.getDate("Due_Date") + "</td>"
                            + "</tr></table></html></body>");
                   
                } else {
                    tstLabel[i].setText("<html> <body> <table width=\"860\"> <tr> <td width=\"30%\"> <u> <span style=\"color:red\">" + rs.getString("T_Name") + "</u> </td>"
                        + "<td width=\"55%\"> <span style=\"color:red\">" + rs.getString("P_Name") +"</td>"
                        + "<td width=\"15%\"> <span style=\"color:red\">" + rs.getDate("Due_Date") + "</td>"
                        + "</tr></table></html></body>");
                }
                tstLabel[i].setName(rs.getInt("Tasks.PID") + ":::" + rs.getString("M_Name") + ":::" + rs.getString("T_Name") + ":::" + rs.getDate("Due_Date") + ":::");
            }           
        }catch(SQLException e){
            System.err.println("Error in Tasks Display");
            System.err.println(e.getMessage());
            }        

        for(int i=0; i<tstLabel.length; i++){
            tstLabel[i].setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
            tstLabel[i].addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                taskMouseClicked(evt);
            }});
        }

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        GroupLayout.SequentialGroup leftToRight = jPanel2Layout.createSequentialGroup();
        GroupLayout.ParallelGroup singleColumn = jPanel2Layout.createParallelGroup();
        for(int i=0; i<tstLabel.length; i++){
            singleColumn.addComponent(tstLabel[i], javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 860, Short.MAX_VALUE);
        }
        leftToRight.addGroup(singleColumn);

        GroupLayout.SequentialGroup topToBottom = jPanel2Layout.createSequentialGroup();
        GroupLayout.ParallelGroup rowTop = jPanel2Layout.createParallelGroup();
        topToBottom.addGroup(rowTop);
        for(int i=0; i<tstLabel.length; i++){
            topToBottom.addComponent(tstLabel[i], javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE);
        }
        jPanel2Layout.setHorizontalGroup(leftToRight);
        jPanel2Layout.setVerticalGroup(topToBottom);
    }

    private Date getDate(){
        Calendar cal = Calendar.getInstance();
        return cal.getTime();        
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel clkEmTskReport;
    private javax.swing.JLabel clkLogout;
    private javax.swing.JLabel clkPrTskReport;
    private javax.swing.JLabel dashboardName;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Label label4;
    private java.awt.Label label5;
    private java.awt.Label label6;
    private java.awt.Label label7;
    private java.awt.Label label8;
    private javax.swing.JPanel myprojectsPanel;
    private javax.swing.JPanel mytasksPanel;
    private javax.swing.JButton newProjectButton;
    // End of variables declaration//GEN-END:variables

}
